﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;

namespace AnyOffice.general.meeting.apply
{
    public partial class _new : ModulePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DataTable table = new MeetingRoomDao().SelectAll(base.Conn);
                this.ddlRoomId.DataSource = table;
                this.ddlRoomId.DataValueField = "RoomId";
                this.ddlRoomId.DataTextField = "Name";
                this.ddlRoomId.DataBind();
                DataTable table2 = new MeetingDao().SelectOperator(base.Conn);
                //this.ddlOperator.DataSource = table2;
                //this.ddlOperator.DataValueField = "UserId";
                //this.ddlOperator.DataTextField = "UserName";
                //this.ddlOperator.DataBind();
                UserCache cache = new UserCache();
                this.txtProposer.Value = cache.UserName;
                this.txtRequestTime.Value = DateTime.Now.ToString("yyyy-MM-dd");
                this.txtStartTime.Value = DateTime.Now.ToString("yyyy-MM-dd");
                this.txtEndTime.Value = DateTime.Now.ToString("yyyy-MM-dd");
              //  this.ckbMobile.Visible = SmsDao.IsMobile(SmsDao.SmsType.Meeting);
                this.ckbMobileRemind.Visible = SmsDao.IsMobile(SmsDao.SmsType.Meeting);
            }
            if (this.Page.IsPostBack)
            {
                MeetingDao dao3 = new MeetingDao();
                MeetingData data = new MeetingData();
                data.Name = this.txtName.Value;
                if (this.txtTopic.Value != string.Empty)
                {
                    data.Topic = this.txtTopic.Value;
                }
                if (this.txtDescription.Value != string.Empty)
                {
                    data.Description = this.txtDescription.Value;
                }
                data.Proposer = base.User.Identity.Name;
                data.RequestTime = DateTime.Now;
                if (this.Attendee.Value != string.Empty)
                {
                    data.Attendee = this.Attendee.Value;
                }
                if (this.txtGuest.Value != string.Empty)
                {
                    data.Guest = this.txtGuest.Value;
                }
                data.StartTime = Convert.ToDateTime(this.txtStartTime.Value);
                data.EndTime = Convert.ToDateTime(this.txtEndTime.Value);
                data.RoomId = Convert.ToInt32(this.ddlRoomId.SelectedValue);
                data.SmsRemind = this.ckbSmsRemind.Checked;
                data.MobileRemind = this.ckbMobileRemind.Checked;
                data.Status = 1;
                dao3.Insert(base.Conn, data);
                if ((this.ckbSmsRemind.Checked || this.ckbMobileRemind.Checked))
                {
                    SmsDao dao4 = new SmsDao();
                    SmsData data2 = new SmsData();
                    data2.Type = 8;
                    data2.FromId = base.User.Identity.Name;
                    data2.ToIdList = this.Attendee.Value.TrimEnd(',');
                    data2.Content = "您有新的会议需要参加：" + this.txtName.Value;
                    data2.SendTime = DateTime.Now;
                    dao4.BizSend(base.Conn, data2, this.ckbSmsRemind.Checked, this.ckbMobileRemind.Checked);
                }
                this.pnlMain.Visible = false;
                this.litMessage.Text = base.ShowPrompt("会议申请添加成功！", "new.aspx");
            }
        }
 

    }
}
